<%@page import="recommend.RecommendHelper"%>
<%@page import="service.CommentService"%>
<%@page import="entities.CommentEntity"%>
<%@page import="service.ScanHistoryService"%>
<%@page import="service.CollectService"%>
<%@page import="entities.GoodsEntity"%>
<%@page import="entities.CartEntity"%>
<%@page import="service.OrderService"%>
<%@page import="entities.OrderEntity"%>
<%@page import="service.UserService"%>
<%@page import="entities.UserEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";

	String userName = (String) session.getAttribute("userName");
	String action = request.getParameter("action");
	UserEntity user = new UserEntity();
		if (userName == null) {
		response.sendRedirect("../logReg.jsp?action=login");
	} else {
		user = UserService.getUser(userName);
		//获得订单数据
	}
	
	//针对分页的
	//每页的记录数
	int pageSize = 10 ;
	//总评论数
	int count  = CommentService.getUserCommentCount(userName);
	//总共的页数 
	int pageCount =count%pageSize==0?count/pageSize:(count/pageSize+1);
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>订单历史-<%=user.getName()%></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js">
	
</script>
<script src="js/GlobalFunction.js" type="text/javascript"></script>
<script type="text/javascript" src="<%=basePath%>user/js/personal.js">
	
</script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/goodsDetail.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/cart.css">
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>user/css/user.css">


<style type="text/css">

/*订单信息*/
.orderInfo {
	border-bottom: 1px solid #ccc;
	padding: 5px;
}

.orderInfo div {
	margin-bottom: 3px;
}

.orderInfo span {
	color: #15ADFF;
	font-size: 14px;
}
/*订单号*/
.orderInfo span.orderNo {
	color: red;
	font-weight: bold;
	font-size: 20px;
	margin-bottom: 10px;
}

.orderInfo .detail {
	font-size: 12px;
	padding: 2px;
	margin-right: 5px;
	color: white;
	background-color: #15ADFF;
}

.orderInfo .detail:hover {
	background-color: #7CDAEF;
	color: red;
}
.page{
	width: 700px;
	text-align: center;
	margin-top: 8px;
    font-size: 14px;
}
.page span{
	padding: 0 6px;
	color: #ff74a9;
}
.page a{
	margin: 0 2px;
}

.page a:hover{
	color: #ff74a9;
}

</style>
</head>

<body>
	<jsp:include page="../header.jsp"></jsp:include>
	<div id="userName" style="height: 30px;"><%=userName%></div>
	<div id="action" style="display: none;"><%=action%></div>
	<div class="center">
		<div class="place">
			<a href="user/index.jsp"><%=userName%>的账户 </a> &gt; 个性化
		</div>
		<div class="leftPanel">
			<div class="userInfo" id="UserInfo">
				<ul>
					<li><a title="设置头像" href="user/userInfo.jsp?action=head"><span
							id="userHead" style="display: none;"><%=user.getHeadImgUrl()%></span><img
							src="<%=user.getHeadImgUrl()%>" alt="头像"> </a>
						<h3>
							[<%=user.getName()%>]
						</h3> 性别：<%=user.getSex()%> <br /><%=user.getCampus()%>校区</li>
					<li><a class="name">手机号码：</a><a class="value"><%=user.getTel()%></a>
					</li>
					<li><a class="name">送餐地址：</a><a class="value"><%=user.getAddr()%></a>
					</li>
					<li><a class="name">注册时间：</a><a class="value"><%=user.getRegTime()%></a>
					</li>
				</ul>
			</div>
			<span class="seperateLine"></span>


			<div class="thirdNav">
				<ul>
					<li id="recommende"><a
						href="user/personalize.jsp?action=recommende">为我推荐</a></li>
					<!-- <li id="analyse"><a href="user/personalize.jsp?action=analyse">购物车分析</a> -->
					</li>
					<li id="scan"><a href="user/personalize.jsp?action=scan">我的浏览历史</a>
					</li>
					<li id="comment"><a href="user/personalize.jsp?action=comment">我发表的评论</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="rightPanel" id="orderList">
			<%
				if ("recommende".equals(action)) {
			%>
			<div class="panelTitle">
				<a>为我推荐</a>
			</div>
			<div class="cart_other_products">
			<div class="mall_box" id="featured_star" style="display: block;">
				<ul class="product_list" id="product_list_star">
					<%
					List<GoodsEntity> goodsList = new ArrayList<GoodsEntity>();
					goodsList = RecommendHelper.getRecommendGoods(userName, 9);
					for(GoodsEntity goods:goodsList) {%>
					<li class="cross_sale_deal">
						<div class="pic">
							<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>"
								target="_blank"><img src="<%=goods.getImageUrl() %>"
								width="160" height="160"> </a>
						</div>
						<div class="name">
							<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>"
								target="_blank"><%=goods.getName() %></a>
						</div>
						<div class="price">
							<span>¥<%=goods.getPrice() %></span>
						</div>
						<div onclick="readyBuy(<%=goods.getId()%>);" id="buy"
							class="button">加入购物车</div></li>

					<%} %>
				</ul>
			</div>
		</div>
			<%
				} else if ("analyse".equals(action)) {
			%>
			<div class="panelTitle">
				<a>购物车分析</a>
			</div>
			<%
				} else if ("comment".equals(action)) {
					String pageIndex  = request.getParameter("pageIndex");
					if(null==pageIndex){
						pageIndex = "1"; 
					}
					int pageNow = Integer.parseInt(pageIndex);
			%>
			<div class="panelTitle">
				<a>我发表的商品评论</a>
			</div>
			<br/>
			<br/>
			<!-- 评论列表 begin -->
			<div class="comments">
				<ul class="comment_list">
					<%
					List<CommentEntity> comments =  new ArrayList<CommentEntity>();
					comments = CommentService.getUserComment(userName, ""+(pageNow - 1)*pageSize, pageSize+"");
					for (int i = 0; i < comments.size(); i++) {
					%>
					<li class="comment">
						<a href="goodsDetail.jsp?goodsId=<%=comments.get(i).getGoodsId()  %>" target="_blank">
							<img class="head" src="<%=comments.get(i).getGoodsImg() %>" alt="<%=comments.get(i).getGoodsName()%>">
						</a>
						<p class="sms">
							<a href="goodsDetail.jsp?goodsId=<%=comments.get(i).getGoodsId()  %>" target="_blank"><%=comments.get(i).getGoodsName()%></a>
							: <span class="comment_title"><%=comments.get(i).getTitle()%></span><span>&nbsp;&nbsp;&nbsp;打分：<b
								style="color: red;"><%=comments.get(i).getRank()%></b> </span>
						</p>
						<p class="sms"><%=comments.get(i).getContent()%><span>&nbsp;&nbsp;&nbsp;<%=comments.get(i).getTime()%></span>
						</p>
					</li>
					<%
					}
					%>
					
				</ul>
				
				<div class="page">
		          	共:<span><%=pageCount %></span>页(共<%=count %>条)；&nbsp;&nbsp;&nbsp;每页<span><%=pageSize %></span>条记录；&nbsp;&nbsp;当前为第<span><%=pageCount==0?0:pageNow%></span>页。<br/>
		          	<%if(pageNow>1){ %>
		            <a href="user/personalize.jsp?action=comment&pageIndex=<%=pageNow-1%>">上一页</a> 
		            <%}else{ %>
		            <a title="没有上一页啦">上一页</a> 
		            <%}
		              if(pageNow<pageCount){ %>
		            <a href="user/personalize.jsp?action=comment&pageIndex=<%=pageNow+1%>">下一页</a> 
		            <%}else{ %>
		            <a title="没有下一页啦">下一页</a> 
		            <%} %>
		            <a href="user/personalize.jsp?action=comment">首页</a>
		            <a href="user/personalize.jsp?action=comment&pageIndex=<%=pageCount==0?1:pageCount%>">末页</a>
			     </div>
			</div>
			<!-- 评论列表 end -->
		</div>
		<%
		}else if("scan".equals(action)){
		%>
		<div class="panelTitle">
			<a>我的浏览记录</a>
		</div>
		<div class="cart_other_products">
			<div class="mall_box" id="featured_star" style="display: block;">
				<ul class="product_list" id="product_list_star">
					<%
					List<GoodsEntity> goodsList = new ArrayList<GoodsEntity>();
					goodsList = ScanHistoryService.selectAll(userName,9); 
					for(GoodsEntity goods:goodsList) {%>
					<li class="cross_sale_deal">
						<div class="pic">
							<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>"
								target="_blank"><img src="<%=goods.getImageUrl() %>"
								width="160" height="160"> </a>
						</div>
						<div class="name">
							<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>"
								target="_blank"><%=goods.getName() %></a>
						</div>
						<div class="price">
							<span>¥<%=goods.getPrice() %></span><span class="discount">(<%=goods.getOnSaleTime()%>)</span>
						</div>
						<div onclick="readyBuy(<%=goods.getId()%>);" id="buy"
							class="button">加入购物车</div></li>

					<%} %>
				</ul>
			</div>
		</div>
		<%} %>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
